﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace common.Controls
{
    public partial class embed : UserControl
    {
        internal static DependencyProperty EmbedIDProperty = DependencyProperty.Register("ID", typeof(string), typeof(embed), new PropertyMetadata("", EmbedChanged));

        private static void EmbedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            embed fls = (embed)d;
            fls.SetEmbedded((string)e.NewValue);
        }

        private void SetEmbedded(string newValue)
        {
            if (!string.IsNullOrEmpty(newValue))
            {
                StringBuilder embeddObj = new StringBuilder();
                embeddObj.AppendFormat(
                    @"<object data=""data:application/x-silverlight-2,"" type=""application/x-silverlight-2"" width=""512"" height=""480"">");
                embeddObj.AppendFormat(
                    @"<param name=""source"" value=""http://gamenes.net/clientbin/gamenesembedd.xap""/>");
                embeddObj.AppendFormat(@"<param name=""InitParams"" value=""g={0}"" />", newValue);
                embeddObj.AppendFormat(@"<param name=""background"" value=""transparent"" />");
                embeddObj.AppendFormat(@"<param name=""minRuntimeVersion"" value=""3.0"" />");
                embeddObj.AppendFormat(@"<param name=""autoUpgrade"" value=""true"" />");
                embeddObj.AppendFormat(@"<param name=""maxframerate"" value=""50"" />");
                embeddObj.AppendFormat(
                    @"<a href=""http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0"" style=""text-decoration: none"">");
                embeddObj.AppendFormat(
                    @"<img src=""http://go.microsoft.com/fwlink/?LinkId=108181"" alt=""Get Microsoft Silverlight"" style=""border-style: none""/> ");
                embeddObj.AppendFormat(@"</a>");
                embeddObj.AppendFormat(@"</object>");
                code.Text = embeddObj.ToString();
                buttonShare.Background = new SolidColorBrush(Colors.Red);
            }
        }

        public string EmbedID
        {
            get
            {
                return (string)GetValue(EmbedIDProperty);
            }
            set
            {
                SetValue(EmbedIDProperty, value);
            }
        }

        public embed()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            shareWindow.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!string.IsNullOrEmpty(EmbedID))
            {
                shareWindow.Visibility = System.Windows.Visibility.Visible;
            }
        }

    }
}
